<!--#include file="lib/utf-8.asp"-->
<!--#include file="lib/conn.asp"-->
<!--#include file="lib/saferequest.asp"-->
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="Expires" content="-1" />
<link type="text/css" rel="stylesheet" href="lib/jquery_datatables_lastest/media/css/demo_page.css" />
<link type="text/css" rel="stylesheet" href="lib/jquery_datatables_lastest/media/css/demo_table.css" />
<link type="text/css" rel="stylesheet" href="lib/jquery_ui_lastest/themes/base/jquery_ui_lastest.css" />
<link type="text/css" rel="stylesheet" href="lib/jquery_fancybox_lastest/fancybox/jquery_fancybox_lastest.css" />
<link type="text/css" rel="stylesheet" href="lib/sheet.css" />
<script type="text/javascript" src="lib/jquery_lastest.js"></script>
<script type="text/javascript" src="lib/jquery_fancybox_lastest/fancybox/jquery_fancybox_lastest.js"></script>
<script type="text/javascript" src="lib/jquery_timers_lastest.js"></script>
<script type="text/javascript" src="lib/jquery_ui_lastest/jquery_ui_lastest.js"></script>
<script type="text/javascript" src="lib/jquery_datatables_lastest/media/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&language=zh-CN&region=CN"></script>
<script type="text/javascript" src="lib/main.js"></script>
<script type="text/javascript">
	$(function() {
				//$(".contable").addClass("ct");	//载入table样式
				//$(".contable th").addClass("ch");	//载入th样式
				//$(".contable td").addClass("cd");	//载入td样式

				//$(".contable tbody tr:odd").addClass("alt");	//对表格主体内单数行进行样式应用

				//$(".contable tbody tr").hover(function(){	//对返回的dom进行hover事件捕获
				//	$(this).addClass("over");	//添加css样式
				//},function(){
				//	$(this).removeClass("over");	//移除css样式
				//});
		//$(".contable tbody tr").live('hover',function(){	//对返回的dom进行hover事件捕获
		//	$(this).toggleClass("over");	//添加css样式
		//});

		function fnFormatDetails ( oTable, nTr )
		{
			var aData = oTable.fnGetData( nTr );
			var sOut;
			sOut = '<table>';
			//sOut += '<tr><td>Rendering engine:</td><td>'+aData[1]+' '+aData[4]+'</td></tr>';
			//sOut += '<tr><td>Link to source:</td><td>Could provide a link here</td></tr>';
			//sOut += '<tr><td>Extra info:</td><td>And any further details here (images etc)</td></tr>';
			
			$.ajax({
				url: "readProgress.asp",
				async: false,
				data: {"progress_cl":aData[1],"range":"2"},
				success: function(data){
					sOut +='<tr style="text-align:center;border-bottom: 1px solid black;">';
					sOut +='<td>货单</td>';
					sOut +='<td>日期</td>';
					sOut +='<td>时间</td>';
					sOut +='<td>地点</td>';
					sOut +='<td>箱型</td>';
					sOut +='<td>派单时间</td>';
					sOut +='<td>接单时间</td>';
					sOut +='<td>提箱时间</td>';
					sOut +='<td>到厂时间</td>';
					sOut +='<td>离场时间</td>';
					sOut +='<td>进港时间</td>';
					sOut +='</tr>';
 					$.each(data,function(i,item){
						sOut +='<tr style="text-align:center;">';
						sOut +='<td><a class="iframe" href="view_cd.asp?id='+item.progress_yb+'">'+item.progress_yb+'</a></td>';
						sOut +='<td>'+item.rq+'</td>';
						sOut +='<td>'+item.sj+'</td>';
						sOut +='<td>'+item.dd+'</td>';
						sOut +='<td>'+item.xx+'</td>';
						sOut +='<td>'+item.progress_start+'</td>';
						sOut +='<td>'+item.progress_accept+'</td>';
						sOut +='<td>'+item.progress_tx+'</td>';
						sOut +='<td>'+item.progress_reach+'</td>';
						sOut +='<td>'+item.progress_left+'</td>';
						sOut +='<td>'+item.progress_arrival+'</td>';
						sOut +='</tr>';
					});
					sOut += '</table>';
				}
			});
			
			
			//$.getJSON("readProgress.asp",{"progress_cl":aData[1]},function(data){
			//	$.each(data,function(i,item){
					//alert(item.progress_yb);
			//		sOut +='<tr><td>'+item.progress_yb+'</td>';
			//		sOut +='<td>'+item.progress_start+'</td>';
			//		sOut +='<td>'+item.progress_accept+'</td>';
			//		sOut +='<td>'+item.progress_tx+'</td></tr>';
				
				
			//	});
			
			//});
			
			
			
			return sOut;
		}
				
				
				
				
				
		var nCloneTh = document.createElement( 'th' );
		var nCloneTd = document.createElement( 'td' );
		nCloneTd.innerHTML = '<img src="lib/jquery_datatables_lastest/examples/examples_support/details_open.png" style="cursor:pointer" />';
		nCloneTd.className = "center";
		
		$('.contable thead tr').each( function () {
			this.insertBefore( nCloneTh, this.childNodes[0] );
		} );
		
		$('.contable tbody tr').each( function () {
			this.insertBefore(  nCloneTd.cloneNode( true ), this.childNodes[0] );
		} );


		oTable = $('.contable').dataTable({
			"iDisplayLength": 50,
			"oLanguage": {
				"sUrl": "lib/jquery_datatables_lastest/media/language/zh_CN.txt"
			},
			"aoColumnDefs": [
				{ "sClass": 'center', "aTargets": [ 0, -1, -2, -3, -5, -6, -7 ] },
				{ "bSortable": false, "aTargets": [ 0, -2, -3, -4 ] }
			],
			"aaSorting": [[1, 'asc']]

		
		});

		$('.contable tbody td img').live('click', function () {
			var nTr = this.parentNode.parentNode;
			if ( this.src.match('details_close') ){
				/* This row is already open - close it */
				oTable.fnClose( nTr );
				this.src = "lib/jquery_datatables_lastest/examples/examples_support/details_open.png";
			}else{
				/* Open this row */
					//oTable.fnOpen( nTr, fnFormatDetails(oTable, nTr), 'details' );
					oTable.fnOpen( nTr, fnFormatDetails(oTable, nTr), 'details' );
					this.src = "lib/jquery_datatables_lastest/examples/examples_support/details_close.png";
					$("a.iframe").fancybox({
						'width':860,
						'height':550,
						'speedOut':0,
						'hideOnOverlayClick':false,
						'type':'iframe'
					});

			}
		});
				
		
		
		//var geocoder = new google.maps.Geocoder();
		
	$(".line").click(function(){
		ip="61.153.145.162:8888";
		line="telcom";
		if($(this).val()=="cnc"){
			ip="221.12.55.171:8889";
			line="cnc";
		}
		
		
		var nNodes = oTable.fnGetNodes( );
		//alert(nNodes.length);
		$.each(nNodes,function(i,item){
			var aData = oTable.fnGetData( item );
			//alert(aData[1]);
			//http://61.153.145.162:8888/getpositionTP.asp?regnum=浙B8E792 
			//电信地址
			//http://221.12.55.171:8889/getpositionTP.asp?regnum=浙B8E792 
			//网通地址
			
			$.getJSON("http://"+ip+"/getpositionTP.asp?regnum="+aData[3]+"&line="+line+"&jsonpcallback=?",function(data){
				if(!jQuery.isEmptyObject(data)){
					lng=data.Geometry.Coordinates[0];
					lat=data.Geometry.Coordinates[1];
					timestamp=ms2date(data.TimeStamp);
					speed=data.Speed;
					mlURL=data.mlURL;
					

					//$.getJSON("http://maps.google.com/maps/api/geocode/json?latlng="+lat+","+lng+"&sensor=false",function(addr){
					$.getJSON("jsonproxy.asp",{"url":"http://maps.google.com/maps/api/geocode/json?latlng="+lat+","+lng+"&sensor=false&region=cn&language=zh-CN"},function(addr){
//					$.getJSON("http://maps.google.com/maps/api/geocode/json?latlng="+lat+","+lng+"&sensor=false&language=zh-CN&jsonpcallback=?",function(addr){
					
						//addr = eval("(" + addr + ")"); 	
						//alert(addr);
						str=addr.results[0].formatted_address;
						str=str.replace(/中国浙江省/,"");
						oTable.fnUpdate( str, i,4 );
					
					});
					

					//oTable.fnUpdate( GetAddrFrom51Ditu(lat,lng), i,4 );
					
/*
					var latlng = new google.maps.LatLng(lat, lng);
					
					if (geocoder) {
						geocoder.geocode({'latLng': latlng}, function(results, status) {
							if (status == google.maps.GeocoderStatus.OK) {
								if (results[0]) {
									oTable.fnUpdate( results[0].formatted_address, i,4 );
								}
							} else {
								//alert("Geocoder failed due to: " + status);
							}
						});
					}					
*/					
					//oTable.fnUpdate( reverse, i,4 );
					oTable.fnUpdate( timestamp, i,5 );
					oTable.fnUpdate( speed+" KM/H", i,6 );
				}
			});
		
		});
		var d=new Date();
		$("#info_bar").html(d.toLocaleString());
	});
		
		$('.contable tbody td a.deal').live('click', function () {
				window.open("deal.asp?clid="+$(this).attr("title"),"_blank","height=640px, width=480px, toolbar=no, menubar=no, scrollbars=yes, resizable=no, location=no, status=no");
			
		});

		
		
		$("#show_list").hide();
		$("#progress_map").hide();
		$("#show_list").click(function(){
			$(".progress_toggle").toggle();
		});
		$("#show_map").click(function(){
			$(".progress_toggle").toggle();
			mapInit();
		});
		$(window).resize(function(){
			mapInit();
		});

		function fitWindow(){
			var h=$(window).height();
			//alert(h);
			h=h-50;
			return h;
		}
		
		var map,infowindow,marker;
		var markerArray = [];
		var infowindowArray = [];
		var clat = 29.868336;
		var clng = 121.54399;
		var bounds; 
		 
		//地图初始化
		function mapInit(){
			var myOptions = {
				zoom : 8,
				center : new google.maps.LatLng(clat, clng),
				mapTypeId : google.maps.MapTypeId.ROADMAP
			};
			$("#progress_map").height(fitWindow());
			map = new google.maps.Map(document.getElementById("progress_map"), myOptions);
			var southWest = northEast = new google.maps.LatLng(clat,clng);
			bounds = new google.maps.LatLngBounds(southWest,northEast);
			getLocation();
			$("#progress_map").ajaxSuccess(function(){
				map.fitBounds(bounds);
			});

			//map.fitBounds(bounds);
		}
		 
		//添加新标记
		function addMarker(location,icon,contentString){
			var myOptions = {
				position : location,
				draggable : false,
				map : map,
				icon : icon
			};
			marker = new google.maps.Marker(myOptions);
			addInfowindow(marker,contentString);
			//将标记压入数组
			markerArray.push(marker);
		}
		
		function addInfowindow(marker,contentString){
			google.maps.event.addListener(marker, 'click', function() {
				//关闭打开的提示
				if (infowindow) infowindow.close();
				infowindow = new google.maps.InfoWindow();
				infowindow.setOptions({
						content: contentString
				});
				
				infowindow.open(map,marker);
			});
			//将标记提示压入数组
			infowindowArray.push(infowindow);
		}
		
		
		function getLocation(){
			$.getJSON("readLocation.asp",function(data){
				$.each(data,function(i,item){
					var myLatLng=new google.maps.LatLng(item.cl_lat,item.cl_lng);
					if(item.cl_speed==0){
						var icon="images/dd-end.png";
					}else{
						var icon="images/dd-start.png";
					}
					var contentString = '<div id="content">'+
						'<h1 id="firstHeading" style="line-height:30px;font-weight:bold;font-size:larger">'+item.cph+'</h1>'+
						'<div id="bodyContent">'+
						'<p>车名：' +item.clm+' '+item.tel+'</p>'+
						'<p>地点：' +item.cl_reverse+'</p>'+
						'<p>车速：' +item.cl_speed+' KM/H</p>'+
						'<p>定位：' +ms2date(item.cl_timestamp)+'</p>'+
						'<p>更新：' +item.cl_update+'</p>'+
						'</div>'+
						'</div>';
					//addInfowindow(contentString);
					addMarker(myLatLng,icon,contentString);
					bounds=bounds.extend(myLatLng);
					//map.fitBounds(bounds);
				});
				
			});
		}
		
	});
</script>	
</head>
<%
call CheckRights(2,1)
%>

<body>
<%
Set rs = Server.CreateObject("ADODB.Recordset")
sql = "select * from (select * from cl where sscd in(8,13)) as a left join (SELECT progress_cl,count(progress_cl) as num FROM progress  where progress_start>(date()-1) group by progress_cl) as b on a.clid=b.progress_cl"
rs.Open sql,conn,1,1
if not rs.eof then cl_update=formatdatetime(rs("cl_update"),1)&" "&TimeValue(rs("cl_update"))
%>
<div>
	本页面数据更新时间为：<span id="info_bar" style="color:red"><%=cl_update%></span>&nbsp;刷新最新数据请根据您的网络接入情况选择按钮：
	<button class="line" value="telcom">电信</button>&nbsp;
	<button class="line" value="cnc">网通</button>&nbsp;
	<button id="show_map" class="progress_toggle">切换到地图模式</button>
	<button id="show_list" class="progress_toggle">切换到列表模式</button>
</div>
<div id="progress_list" class="progress_toggle">
	<table class="contable display">
		<thead>
			<tr>
				<th>序号</th>
				<th>车辆名</th>
				<th>车牌号</th>
				<th>目前位置</th>
				<th>定位时间</th>
				<th>车速</th>
				<th>工单数</th>
			</tr>
		</thead>
		<tbody>
<%
do while not rs.eof
%>
			<tr>
				<td><%=rs("clid")%></td>
				<td><a class="deal" href="#" title="<%=rs("clid")%>"><%=rs("clm")%></a></td>
				<td><%=rs("cph")%></td>
				<td><%=rs("cl_reverse")%></td>
				<td><%
					if rs("cl_timestamp")<>"" then
						cl_timestamp=cdbl(rs("cl_timestamp"))/1000
						
						response.write(dateadd("s",cl_timestamp,"1970-1-1 0:0:0"))
					end if
				%></td>
				<td><%=rs("cl_speed")%>&nbsp;KM/H</td>
				<td><%=rs("num")%></td>
			</tr>
<%
	rs.movenext
loop
%>
		</tbody>
	</table>
</div>
<% 
rs.close
set rs=nothing
conn.close
Set conn=nothing
%>
<div id="progress_map" class="progress_toggle" style="width:100%;height:640px"></div>
</body>
</html>
